﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;



namespace project
{
    public partial class Login : Form
    {

        public Login()
        {
            InitializeComponent();
             //skinEngine1.SkinFile = "SteelBlack.ssk";
            skinEngine1.SkinFile = Application.StartupPath + @"/Skins/SteelBlack.ssk";
        }
       

        private void pictureBox1_Paint_1(object sender, PaintEventArgs e)
        {
            //设置Label为无色
         PictureBox pb = (PictureBox) sender;
            foreach (Control c in Controls)
            {
                if (c is Label)
                {
                    c.Visible = false;
                    e.Graphics.DrawString(c.Text, c.Font, new SolidBrush(c.ForeColor), c.Left - pb.Left, c.Top - pb.Top);
                }
            }
        }
        //定义一个方法
        private void Self() 
        {
            //创建数据集对象
            DataSet ds = new DataSet();
            //创建连接字符串
            string connstring = "server=;DatsBase=;Integrated Security=true;";
            //创建连接对象
            SqlConnection conn = new SqlConnection(connstring);
            //SQL命令
            string sql = "";
            //创建适配器
            SqlDataAdapter dap = new SqlDataAdapter(sql,conn);
            //填充数据集
            dap.Fill(ds);
            //关闭连接对象
            conn.Close();

        }
        private void button1_Click(object sender, EventArgs e)
        {
            string name= this.textBoxName.Text;
            string pswd = this.textBoxPassword.Text;
            string select= this.comboBox1.SelectedItem.ToString();
            string sql = "SELECT * FROM [dbo].[AdminTable] a join Department d on a.DepartmentNo=d.DepartmentNo Where a.AdminName='{0}'";
            sql = string.Format(sql,name);
            //查询数据库
            DataTable dt= DBHelper.GetTable(sql);
            if (dt.Rows.Count>0)
            {
                if (select== dt.Rows[0]["DepartName"].ToString())
                {
                    if (dt.Rows[0]["Password"].ToString() == pswd)
                    {
                        Home form2 = new Home();
                        this.Hide();
                        form2.Show();
                        return;
                    }
                }
                
                
            }
            MessageBox.Show("用户名或者密码错误");



        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void btn_quxiao_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定取消吗?", "提示信息",MessageBoxButtons.YesNo);
            if (result==DialogResult.Yes)
            {
                Close();
            }
            else
            {
             
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.comboBox1.Items.Add("管理部");
            this.comboBox1.Items.Add("销售部");
            this.comboBox1.Items.Add("库存部");
            this.comboBox1.SelectedIndex = 0;
        

        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            System.Environment.Exit(0);
        }

        private void lbl_si_Click(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void lbl_san_Click(object sender, EventArgs e)
        {

        }

        private void lbl_er_Click(object sender, EventArgs e)
        {

        }

    }
}
